home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / oct90.arc / FOLD.LSP < prev    next >
Text File  |  1990-11-01  |  8KB  |  372 lines

  1. ; Fold.Lsp   [Article Figure 2]   (c)1990, Phil Kreiker
  2.  
  3. ; COPYRIGHT 1990 BY
  4. ; LOOKING GLASS MICROPRODUCTS
  5. ;
  6. (Setq
  7.    version "1.0"
  8.    <180    Pi
  9. )
  10. ;---------------------------------------
  11. ; Load-time chewing gum
  12. ;---------------------------------------
  13. (Princ "\n")
  14. (Setq bcount 0)
  15. (Defun bump ()
  16.    (Setq bcount (1+ bcount))
  17.    (Princ
  18.       (Strcat
  19.          "\rFold version "
  20.          version
  21.          " -- Copyright 1990
  22. by Looking Glass Microproducts : "
  23.          (ItoA bcount)
  24.       )
  25.    )
  26. )
  27. ;---------------------------------------
  28. ; Item from association list
  29. ;---------------------------------------
  30. (bump)
  31. (Defun item (n e)
  32.    (CDR (Assoc n e))
  33. )
  34. ;---------------------------------------
  35. ; Error Handler
  36. ;---------------------------------------
  37. (bump)
  38. (Defun bend-error (s)
  39.    (If (/= S "Function cancelled")
  40.       (Princ s)
  41.    )
  42.    (Command)
  43.    (Command)
  44.    (Command ".UNDO" "e")
  45.    (If undoit
  46.       (Progn
  47.          (Princ "\nUndoing...")
  48.          (Command ".U")
  49.       )
  50.    )
  51.    (moder)
  52. )
  53. ;---------------------------------------
  54. ; System variable save
  55. ;---------------------------------------
  56. (bump)
  57. (Defun modes (a)
  58.    (Setq MLST Nil)
  59.    (Repeat
  60.       (Length a)
  61.       (Setq
  62.          MLST (Append
  63.                  MLST
  64.                  (List
  65.                     (List
  66.                        (CAR a)
  67.                        (GetVar (CAR a))
  68.                     )
  69.                  )
  70.               )
  71.       )
  72.       (Setq a (CDR a))
  73.    )
  74. )
  75. ;---------------------------------------
  76. ; System variable restore
  77. ;---------------------------------------
  78. (bump)
  79. (Defun moder ()
  80.    (Repeat
  81.       (Length MLST)
  82.       (Setvar
  83.          (CAAR MLST) (CADAR MLST)
  84.       )
  85.       (Setq MLST (CDR MLST))
  86.    )
  87.    (Setq *Error* olderror)
  88.    (Princ)
  89. )
  90. ;---------------------------------------
  91. ; System variable set
  92. ;---------------------------------------
  93. (bump)
  94. (Defun setvars (mlst)
  95.    (Repeat
  96.       (Length MLST)
  97.       (Setvar
  98.          (CAAR MLST) (CADAR MLST)
  99.       )
  100.       (Setq MLST (CDR MLST))
  101.    )
  102. )
  103. ;---------------------------------------
  104. ; Radians to Degrees
  105. ;---------------------------------------
  106. (bump)
  107. (Defun rtod (x)
  108.    (/ (* 180.0 x) <180)
  109. )
  110. ;---------------------------------------
  111. ; Mark vertices with points
  112. ;---------------------------------------
  113. (bump)
  114. (Defun markverts (pname / ent ename ss1)
  115.    (Command ".ucs" "w")
  116.    (Setq
  117.       ent   (EntGet pname)
  118.       Ename pname
  119.       ss1   (SsAdd)
  120.    )
  121.    (While (=
  122.              "VERTEX"
  123.              (item
  124.                 0
  125.                 (Setq
  126.                    Ename (EntNext Ename)
  127.                    ent   (EntGet Ename)
  128.                 )
  129.              )
  130.           )
  131.       (Redraw ename 3)
  132.       (Command
  133.          ".point"
  134.          (item 10 ent)
  135.       )
  136.       (SsAdd (EntLast) ss1)
  137.    )
  138.    (Redraw pname)
  139.    (Command ".ucs" "p")
  140.    ss1
  141. )
  142. ;---------------------------------------
  143. ; Bold vertices to points
  144. ;---------------------------------------
  145. (bump)
  146. (Defun bendverts (pname ss1
  147.       / ent ename i pntname pntent)
  148.    (Setq
  149.       ent   (EntGet pname)
  150.       Ename pname
  151.       i     0
  152.    )
  153.    (While (=
  154.              "VERTEX"
  155.              (item
  156.                 0
  157.                 (Setq
  158.                    Ename (EntNext Ename)
  159.                    ent   (EntGet Ename)
  160.                 )
  161.              )
  162.           )
  163.       (Redraw ename 3)
  164.       (Setq
  165.          pntname (SsName ss1 i)
  166.          i       (1+ i)
  167.          pntent  (EntGet pntname)
  168.       )
  169.       (EntMod
  170.          (Subst
  171.             (Assoc 10 pntent)
  172.             (Assoc 10 ent)
  173.             ent
  174.          )
  175.       )
  176.    )
  177.  
  178.    ; Force a regen of the mesh such that
  179.    ; undo and redo will regen.
  180.    ; Entupd won't make it
  181.    (Command
  182.       ".move" meshname ""
  183.       '(0 0 0) ""
  184.    )
  185. )
  186. ;---------------------------------------
  187. ; Returns the selection set of all
  188. ; entities which are members of both
  189. ;ss1 and ss2.
  190. ;---------------------------------------
  191. (bump)
  192. (Defun meet (ss1 ss2 / pt1 ssa ssb)
  193.    (If (And ss1 ss2)
  194.       (Progn
  195.          (Command
  196.             ".point"
  197.             (GetVar "viewctr")
  198.          )
  199.          (Setq pt1 (EntLast))
  200.          (Command
  201.             ".select" pt1 ss1 "r" ss2 ""
  202.          )
  203.          (Setq ssa (SsGet "P"))
  204.          (SsDel pt1 ssa)
  205.          (Command
  206.             ".select" pt1 ss1 "r" ssa ""
  207.          )
  208.          (Setq ssb (SsGet "P"))
  209.          (SsDel pt1 ssb)
  210.          (EntDel pt1)
  211.          (If (> (SsLength ssb) 0) ssb)
  212.       )
  213.    )
  214. )
  215. ;---------------------------------------
  216. ; GET A 3D MESH OR 3D POLYLINE
  217. ;---------------------------------------
  218. (bump)
  219. (Defun getmesh (/ again ename ent)
  220.    (Setq again T)
  221.    (While again
  222.       (If (Setq
  223.              ename (CAR
  224.                       (EntSel
  225. "\nSelect a mesh or 3D polyline: "
  226.                       )
  227.                    )
  228.           )
  229.          (Progn
  230.             (Setq ent (EntGet ename))
  231.             (If (And
  232.               (= (item 0 ent)"POLYLINE")
  233.               (>= (item 70 ent) 8)
  234.                 )
  235.                (Progn
  236.                  (Setq again Nil) ename)
  237.                (Princ
  238. "\nNot a mesh or 3D polyline."
  239.                )
  240.             )
  241.          )
  242.          (Setq again Nil)
  243.       )
  244.    )
  245. )
  246. ;---------------------------------------
  247. ; GET FOLD LINE
  248. ;---------------------------------------
  249. (Defun getbendline (/ p1 p2)
  250.    (While (= p1 p2)
  251.       (InitGet 1)
  252.       (Setq
  253.          p1 (GetPoint
  254. "\nFirst point of fold line: "
  255.             )
  256.       )
  257.       (InitGet 1)
  258.       (Setq
  259.        p2 (GetPoint p1 "Second point: ")
  260.       )
  261.       (If (= p1 p2)
  262.          (Princ
  263.             "\nPoints must be distinct."
  264.          )
  265.       )
  266.    )
  267.    (List p1 p2)
  268. )
  269. ;---------------------------------------
  270. ; BEND MAIN ROUTINE
  271. ;---------------------------------------
  272. (bump)
  273. (Defun bend (/ ss1 ss2 meshname ok
  274.       undoit bendline)
  275.    (Setq
  276.       meshname (getmesh)
  277.       ok       meshname
  278.    )
  279.    (If ok
  280.       (Progn
  281.          (Setq bm (GetVar "blipmode"))
  282.          (Setvar "blipmode" 0)
  283.          (Setvar "highlight" 0)
  284.          ;
  285.          (Setq
  286.             undoit T
  287.             ss1    (markverts meshname)
  288. ; place a point on each vertex
  289.          )
  290.          (Setvar "blipmode" bm)
  291.          (Prompt
  292.             "\nSelect vertices..."
  293.          )
  294.          (Setq
  295.             ss2 (meet (SsGet) ss1)
  296. ; get the vertices we wish to fold
  297.             ok  ss2
  298.          )
  299.       )
  300.    )
  301.    (If ok
  302.       (Progn
  303.          (Setq bendline (getbendline))
  304. ; get the fold line
  305.          (Command
  306.             ".ucs" "za"
  307.             (CAR bendline)
  308.             (CADR bendline)
  309.          )
  310.          (InitGet 1)
  311. ; get the fold angle
  312.          (Setq
  313.             ang (rtod
  314.                    (GetAngle
  315.                       '(0 0 0)
  316.                       "\nFold angle: "
  317.                    )
  318.                 )
  319.          )
  320.          (Setvar "pdmode" 1)
  321.          (Command
  322. ; rotate the vertices we wish to fold
  323.             ".rotate" ss2 ""
  324.             '(0 0 0) ang
  325.          )
  326.          (Command ".ucs" "p")
  327.          (bendverts meshname ss1)
  328. ; fold the mesh
  329.       )
  330.    )
  331.    (If ss1
  332.       (Command ".erase" ss1 "")
  333. ; remove the markers
  334.    )
  335.    (Setq ss1 Nil ss2 Nil)
  336. )
  337. ;---------------------------------------
  338. ; BEND COMMAND
  339. ;---------------------------------------
  340. (bump)
  341. (Defun c:fold (/ olderror undoit)
  342.    (modes
  343.       '("cmdecho"
  344.          "osmode"
  345.          "flatland"
  346.          "elevation"
  347.          "thickness"
  348.          "blipmode"
  349.          "highlight"
  350.          "pdmode"
  351.       )
  352.    )
  353.    (Setq
  354.       olderror *Error*
  355.       *Error*  bend-error
  356.    )
  357.    (setvars
  358.       '(("cmdecho" 0)
  359.          ("osmode" 0)
  360.          ("flatland" 0)
  361.          ("elevation" 0.0)
  362.          ("thickness" 0.0)
  363.       )
  364.    )
  365.    (Command ".undo" "group")
  366.    (bend)
  367.    (Command ".undo" "e")
  368.    (moder)
  369. )
  370. (c:fold)
  371. 
  372.